package com.dev;
import android.content.ClipData;
import android.graphics.Typeface;
import android.text.SpannableStringBuilder;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
class ShowImageDetails extends LinearLayout implements OnClickListener {
	WindowManager.LayoutParams wlp=new WindowManager.LayoutParams();
	MainActivity ma;
	ImageManipulationTab imt;
	LinearLayout titlebar;
	LayoutParams titlebarlp;
	TextView title;
	TextView msg;
	IconViewClose close;
	ClickableSpan cs;
	ShowImageDetails(MainActivity ma){
		super(ma);
		this.ma=ma;
		setOrientation(1);
		setBackgroundDrawable(new GUI.BorderDrawable());
		close=new IconViewClose(ma);
		close.setOnClickListener(this);
		title=new TextView(ma);
		title.setTextColor(0xff000000);
		title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
		title.setGravity(Gravity.CENTER_VERTICAL);
		title.setPadding(9, 0, 0, 0);
		title.setText("图像详情");
		titlebar=new LinearLayout(ma);
		titlebar.setOrientation(HORIZONTAL);
		titlebar.addView(title,new LayoutParams(0,-1,1f));
		titlebar.addView(close);
		titlebar.setBackground(new GUI.BorderDrawable());
		titlebarlp=new LayoutParams(-1,ma.dialogTitleBarHeight);
		msg=new TextView(ma);
		msg.setTypeface(Typeface.MONOSPACE);
		msg.setTextColor(0xff000000);
		msg.setTextSize(TypedValue.COMPLEX_UNIT_DIP,13);
		msg.setPadding(9,0,0,0);
		msg.setMovementMethod(LinkMovementMethod.getInstance());
		addView(titlebar,titlebarlp);
		addView(msg,-1,-2);
	}
	void show(ImageManipulationTab imt){
		this.imt=imt;
		wlp.width=ma.wp*2/3;
		wlp.height=-2;
		File src=imt.im.src;
		SpannableStringBuilder ssb=new SpannableStringBuilder("文件路径：");
		final String path=src.getAbsolutePath();
		ssb.append(path+'\n');
		ssb.append("文件大小：");
		long len=src.length();
		ssb.append(len+"B");
		if(len>1024){
			if(len>1024*1024){
				ssb.append("("+len/1024/1024+"MB)");
			}else{
				ssb.append("("+len/1024+"KB"+")");
			}
		}
		ssb.append('\n');
		ssb.append("图像宽度:"+imt.imp.cv.image.getWidth()+'\n');
		ssb.append("图像高度:"+imt.imp.cv.image.getHeight()+'\n');
		cs=new ClickableSpan(){
			@Override
			public void onClick(View v){
				ClipData cd=ClipData.newPlainText(ma.CLIPBOARD_TAG,path);
				ShowImageDetails.this.ma.cm.setPrimaryClip(cd);
				Toast.makeText(ShowImageDetails.this.ma,"file path is copied",0).show();
			}
		};
		ssb.setSpan(cs,5,path.length()+5,0);
		msg.setText(ssb);
		ma.wm.addView(this,wlp);
	}
	void dismiss(){
		ma.wm.removeView(this);
	}
	@Override
	public void onClick(View view) {
		if(view==close){
			dismiss();
		}
	}
}
